﻿Namespace PL.TSMSDK
    Public Interface IPersons_PL
        Sub CreatePersonToProduct(ByVal personID As Guid)
    End Interface

    Public Class Persons_PL
        Inherits PLBase
        Implements IPersons_PL

        Public Sub New()
            MyBase.New()
        End Sub

        Public Sub New(ByVal queryName As String)
            MyBase.New(queryName)
        End Sub

        Sub OnRowUpdating(ByVal sender As Object, ByVal e As SqlRowUpdatingEventArgs) Handles MetaDataTable.OnRowUpdating
        End Sub

        Public Overrides Function Delete() As Boolean
            'Throw New NotImplementedException("Delete To Come...")
            Return False
        End Function

        Public Overrides Function Validate() As Boolean
            'Throw New NotImplementedException("Validate To Come...")
            Return True
        End Function

        Public Overrides Sub ValidateRow(row As DataRow)
            row.ClearErrors()

            If row.Table.Columns.Contains("UserPrincipalName") Then
                If IsDBNull(row("UserPrincipalName")) Then
                    row.SetColumnError("UserPrincipalName", "Mandatory")
                End If
            End If
            '
            If row.HasErrors Then
                row.RowError = "Please check your columns, a validation error occur"
            End If
        End Sub


        Public Overridable Sub CreatePersonToProduct(ByVal personID As Guid) Implements IPersons_PL.CreatePersonToProduct
            Dim sqlcmd As SqlClient.SqlCommand = Nothing
            Try
                'Attention la liste ProductGroupe doit être a IsSequence = True
                sqlcmd = MetaQuery.GetSPCmdByMetaName("CreatePersonToProduct") 'bsp_CreatePersonToProduct_PL_Save
                sqlcmd.Parameters("@PersonID").Value = personID
                sqlcmd.ExecuteReader(CommandBehavior.CloseConnection)
            Catch sqlex As SqlClient.SqlException
                Throw sqlex
            Finally
                If sqlcmd IsNot Nothing Then
                    sqlcmd.Connection.Close()
                    sqlcmd.Dispose()
                End If
            End Try

        End Sub


    End Class
End Namespace
